package model;

/**
 * @author  megea
 */
public class LevelSensor extends Recognizable{
    Double level;
    /**
     * @uml.property  name="criteria"
     * @uml.associationEnd
     */
    Criteria criteria;
    /**
     * @uml.property  name="sensor"
     * @uml.associationEnd
     */
    Sensor sensor;
    public LevelSensor(Double level, Criteria criteria, Sensor sensor, Integer id) {
        super(id);
        this.level = level * sensor.getSource().getMaxValue();
        this.criteria = criteria;
        this.sensor = sensor;
    }

    public Boolean isLevelReached(){
        Boolean result = Boolean.FALSE;
        switch (criteria){
        case HIGHER:
            if (sensor.getSensedValue().getValue().doubleValue() >= level.doubleValue()) {
                result = Boolean.TRUE;
            }
            break;
        case LOWER:
            if (sensor.getSensedValue().getValue().doubleValue() <= level.doubleValue()) {
                result = Boolean.TRUE;
            }
            break;
        }

        return result;
    }

}
